﻿using Mode;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
/// <summary>
/// 用户数据访问类
/// </summary>
    public class UserInfoDAL
    {
        SqlCommand cmd = new SqlCommand();//定义Command对象   
        /// 用户登录验证方法
       
        public  bool  UserLogin(string userid,string password)
        {
            
            cmd.CommandType = System.Data.CommandType.Text;//查询方式选用SQL语句
            cmd .CommandText ="SELECT*FROM UserInfo WhERE userId'"+userid+ "'and pwd='"+password +"'";
            try
            {
                object returnResult = DBHelper.GerScalar(cmd);//创建returnResult对象、储存SQL执行结果
                if (Convert.ToInt64(returnResult) > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userid">用户号</param>
        /// <param name="userName">用户账号</param>
        /// <returns>用户信息数据集</returns>

        public DataSet GetUserInfo(string userid=null ,string userName=null )
        {
            userinfo obj = new userinfo();
            if (userid == null)
                obj.userId = "";
            else obj.userId = userid;
            if (userName == null)
                obj.userName = "";
            else obj.userName = userName;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "GetUserInfo";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@userid", SqlDbType.VarChar, 11).Value = obj.userId;
            cmd.Parameters.Add("@userName", SqlDbType.VarChar, 20).Value = obj.userName;

            DataSet ds = DBHelper.GetDataSet(cmd);
            return ds;
        }
        public MemoryStream GetPhotoByUserID(string userid)
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText= "GetPhotoByUserID";
            cmd.Parameters.Clear();
                cmd.Parameters.Add("@userid", SqlDbType.VarChar, 11).Value = userid;
            if (DBHelper.GetPhotoByUserID(cmd) != null)
                return DBHelper.GetPhotoByUserID(cmd);
            else
                return null;
        }
    }
}
